/*
 * @(#)Component.java 0.0.1-SNAPSHOT
 *
 * Copyright 2009 Telefónica I+D.
 */
package edu.upf.grupE.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * <p>This class implements a Component Interface. In this case this component  is
 * a simple Calculator.</p>
 *
 * <p>Sample:</p>
 * <PRE>
 *    Component component = new edu.upf.grupE.Component();
 *    System.out.println(component.add(5.0,3.0));
 *    System.out.println(component.substract(5.0,3.0));
 * </PRE>
 *
 * @version    0.0.1-SNAPSHOT
 * @author     ${developerName}
 */

public final class Component implements edu.upf.grupE.Component {
     /**
     *  The logger. A new logger <code>edu.upf.grupE.Component</code> is created to add the logs of this Component
     */
	private final static Log log = LogFactory.getLog(Component.class);
    /**
    * This method calculates the added of two numbers
    * @param a first operand
    * @param b second operand
        * @return The added of  <TT>a</TT> and <TT>b</TT>
    */
    @Override
	public double add(final double a, final double b) {
        if (log.isDebugEnabled()){
            log.debug("Calculando la suma de [" + a + "] y [" + b + "]");
        }
		final double result = a+b;
        if (log.isDebugEnabled()){
            log.debug("Resultado=" + result);
        }
        return result;
    };
	
	/**
	 * This method calculates the square root of a number
	 * @param a Primer operando
         * @return  The square root of <TT>a</TT> 
         * @exception  IllegalArgumentException This exception is launched when <TT>a<TT> is a negative number.
	 */
    public double sqrt(final double a){
        if (log.isDebugEnabled()){
            log.debug("Calculando la raíz cuadrada de [" + a + "]");
        }
        if (a < 0){
            throw new IllegalArgumentException("The operand is a negative number");
        }
        return Math.sqrt(a);
    };
}
